<template>
  <div class="lookDetails">
    <h3 class="title">{{title}}</h3>
    <div class="content" v-html="content"></div>
    <div style="marginTop: 20px">
      <div class="attachsItem" v-for="(item, index) in attachsObj" :key="index">
        <a :href="doMain + item.filePath" target="_blank" download>{{item.fileName}}</a>
        <span title="预览" v-preview.delete="[item.fileName, doMain + item.filePath]"><i style="font-size:12px;margin-left:8px;cursor:pointer" class="V7_iconfont V7_iconV7tubiao_kejian"></i></span>
      </div>
    </div>
  </div>
</template>
<script lang="ts">
import { Component, Vue } from 'vue-property-decorator'
import { KmModule } from '@/store/modules/km/index'
@Component({
  name: 'lookDetails'
})
export default class LookDetails extends Vue {
  private $bus: any
  private $store: any

  private title: string = ''

  private content: string = ''

  private doMain: string = ''

  private attachsObj: any = []

  private mounted () {
    this.$bus.$on('lookDetails', (obj: any) => {
      if (obj.importType === 'knowledge_mgt_channel') {
        const actionData = { url: '/im-km/action/item/show', method: 'POST', data: { itemId: obj._id, kmType: 'inner' } }
        KmModule.KmCommonAction(actionData).then(res => {
          if (res && res.success && res.data.row) {
            this.title = res.data.row.title || ''
            this.content = res.data.row.content || ''
            this.attachsObj = res.data.row.attachs || []
          }
        })
      } else {
        this.title = obj.title || ''
        this.content = obj.content || ''
      }
    })
    const initConfig = this.$store.state.common.initConfig
    const doMain = initConfig && initConfig.qiniuDomainMap ? initConfig.qiniuDomainMap.im : '' // 获取当前上传域名
    this.doMain = doMain + '/'
  }

  private beforeDestroy () {
    this.$bus.$off('lookDetails')
  }
}
</script>
<style lang="stylus" scoped>
  .lookDetails
    height calc(100% - 40px)
    overflow auto
    .title
      text-align center
      padding 20px 0px
    .content
      padding 10px
    .attachsItem
      padding 8px 9px
      background #F1F8FD
      border-radius 4px
      color #008BEE
      display inline-block
      margin 0px 10px 10px 0px
</style>
